<template>
  <div>
    <div class="page">
      <!-- <iframe
        class="wxPayUrl"
        :src="wxPayUrl"
        sandbox="allow-scripts allow-top-navigation allow-same-origin"
      ></iframe>-->
    </div>
  </div>
</template>
<script>
  import Pay from '@/dll/pay'

  export default {
    name: 'pay',
    data () {
      return {
        tradeNo: '',
        orderSn: '',
        pageFrom: 'order_confirm'
      }
    },
    created () {
      this.pageFrom = this.$route.query.pageFrom
      this.init()
    },
    methods: {
      init () {
        this.tradeNo = this.$route.params.tradeNo
        this.orderSn = this.$route.params.orderSn
        this.queryWxPayState()
      },
      back () {
        if (this.pageFrom == 'order_confirm') {
          this.$router.back()
        } else {
          this.$router.replace({
            name: 'mallOrder',
            params: { tabIndex: 1 }
          })
        }
      },
      async queryWxPayState () {
        let param = {
          trade_no: this.tradeNo,
          order_sn: this.orderSn,
          pay_type: 'JSAPI'
        }
        this.$vux.loading.show({ text: '支付结果查询中...' })
        let res = await Pay.queryWxPayState(param)
        this.$vux.loading.hide()

        if (res.code == 0) {
          this.$vux.alert.show({
            title: '提示',
            content: '支付成功',
            onHide: () => {
              this.$router.replace({
                name: 'mallOrder',
              })
            }
          })
        } else {
          this.$vux.alert.show({
            title: '提示',
            content: res.msg,
            onHide: () => {
              this.$router.replace({
                name: 'mallOrder',
              })
            }
          })
        }
      }
    }
  }
</script>
<style lang="less" scoped>
  .wxPayUrl {
    margin: 0;
    padding: 0;
    height: 100vh;
    width: 100vw;
    border: none;
  }
</style>
